/*
 * @Description:
 * @Author:Huang Xin Ming
 * @Date:2024-11-07 16:30:46
 * @LastEditors:Huang Xin Ming
 * @LastEditTime:2024-11-11 13:57:32
 */
import { ref } from 'vue'
import type { globalNotifyOptions } from '@/components/GlobalNotify/type'


const globalNotifyState = ref<boolean>(false)
const options = ref()
let timer: NodeJS.Timeout;
export function useNotify () {
    function showNotify(o: globalNotifyOptions) {
        clearTimeout(timer)
        options.value = o
        globalNotifyState.value = true
        if(options.value.duration !== false) {
            timer = setTimeout(() => {
                globalNotifyState.value = false
            }, options.value.duration || 3000)
        }
    }
    function hideNotify() {
        globalNotifyState.value = false
    }
    return {
        globalNotifyState,
        showNotify,
        hideNotify,
        options
    }
}